﻿using System;
using System.Diagnostics;
using System.IO;
using com.bodurov.SessionRecovery.Interfaces;

namespace com.bodurov.SessionRecovery.Tests.Utils
{
    /// <summary>
    /// There is no practical reason for using this class instead of just
    /// changing config file settings but I do that to test changing a Unity
    /// Framework controlled component. All the methods and properties are 
    /// the same as the original except SessionFilesFolder property
    /// </summary>
    public class TestSessionRecoveryConfiguration : ISessionRecoveryConfiguration
    {
        private readonly ISessionRecoveryConfiguration _original = new SessionRecoveryConfiguration();
        public string SessionFilesFolder
        {
            get
            {
                var dir = new DirectoryInfo("../../SavedSessionsFolder");
                return dir.FullName;
            }
        }

        public int NumMinutesAfterWhichRestorIsNotAllowed
        {
            get { return this._original.NumMinutesAfterWhichRestorIsNotAllowed; }
        }

        public string LogFileName
        {
            get { return Path.Combine(SessionFilesFolder, SessionRecoveryConfiguration.CurrentLog); }
        }

        public TraceLevel TraceLevel
        {
            get { return this._original.TraceLevel; }
        }

        public int MaxNumberLogsToKeep
        {
            get { return this._original.MaxNumberLogsToKeep; }
        }

        public string GetFileName(string sessionID)
        {
            return Path.Combine(SessionFilesFolder,
                                DateToString(DateTime.UtcNow) + 
                                SessionRecoveryConfiguration.SplitterChar + 
                                sessionID + 
                                SessionRecoveryConfiguration.FileExtension); ;
        }

        public string DateToString(DateTime date)
        {
            return this._original.DateToString(date);
        }

        public DateTime StringToDate(string str)
        {
            return this._original.StringToDate(str);
        }

        public string GetSessionIdByFileName(string fileName)
        {
            return this._original.GetSessionIdByFileName(fileName);
        }

        public DateTime GetDateTimeByFileName(string fileName)
        {
            return this._original.GetDateTimeByFileName(fileName);
        }

        public bool FileIsSessionFile(string fileName)
        {
            return this._original.FileIsSessionFile(fileName);
        }
    }
}
